<template>
  <div class="tab">
    <div class="record-detail">
      <div class="limit-top">
        <div><span class="limit-desc">{{$t('member.components.title31')}}</span>{{ memberInfo.availableAuthorizationLimit }}</div>
        <div><span class="limit-desc">{{$t('member.components.title32')}} </span>{{ memberInfo.usedAuthorizationLimit }}</div>
        <div><span class="limit-desc">{{$t('member.components.title33')}}</span>{{ memberInfo.authorizationLimit }}</div>
        <div class="table-top">
          <div><span class="limit-desc">{{$t('member.fields.title7')}} </span>{{memberInfo.limitEffectTime | fmt_form_date}} {{$t('common.base.to')}} {{memberInfo.limitExpirationTime| fmt_form_date }} </div>
          <div class="cause-select">
            <div>{{$t('member.components.title34')}}</div>
            <el-select v-model="tableObj.value" :placeholder="$t('common.base.pleaseSelect')" clearable @change="causeChange">
              <el-option
                v-for="item in limitAddOnConfig.changeCause"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </div>
        </div>
        
      </div>
      <el-table
          stripe
          v-loading="listLoading"
          :data="tableObj.list"
          :highlight-current-row="false"
          border
          class="point-table"
          ref="multipleTable"
        >
          <template slot="empty">
            <BaseListForNoData
              v-show="!listLoading"
              :notice-msg="$t('common.base.noData')"
            ></BaseListForNoData>
          </template>
          <template v-for="(column, index) in limitAddOnConfig.columns">
            <el-table-column
              :key="`${column.field}_${index}`"
              :label="column.label"
              :prop="column.field"
              :min-width="column.minWidth || '120px'"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <template v-if="column.field === 'createTime'">
                  {{ scope.row[column.field] | formatTime}}
                </template>
                <template v-if="column.field === 'changeCause'">
                  {{ scope.row[column.field] | causeFormat}}
                </template>
                <template v-else>
                  <div>
                    {{ scope.row[column.field] }}
                  </div>
                </template>
              </template>
            </el-table-column>
          </template>
        </el-table>
        <el-pagination
          class="product-table-pagination"
          background
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
          :page-sizes="[10, 20, 50]"
          :page-size="tableObj.pageSize"
          :current-page="tableObj.pageNum"
          layout="prev, pager, next, sizes, jumper"
          :total="tableObj.total"
        >
        </el-pagination>
    </div>
  </div>
</template>

<script>
import { limitAddOnConfig } from '@src/modules/member/detail/addConfiguration.js';
import { searchLimitConsume } from '@src/api/Member'
import RecordMixin from '@src/modules/member/mixins/record.js';
import dayjs from 'dayjs'
export default {
  name: 'limit-record',
  mixins: [RecordMixin],
  props: {
    memberInfo: {
      type: Object,
      default: {}
    },
  },
  data() {
    return {
      limitAddOnConfig,
      listLoading: false,
      tableObj: {
        list: [],
        value: '',
        pageSize: 10,
        pageNum: 1,
        total: 0
      }
    };
  },
  filters: {
    formatTime(time) {
      if (!time) return
      return dayjs(time).format('YYYY-MM-DD HH:mm:ss')
    }
  },
  methods: {
    causeChange() {
      this.tableObj.pageNum = 1
      this.getTableData()
    },
    async getTableData() {
      let param = {
        membershipId: this.memberInfo.id,
        changeCause: this.tableObj.value,
        pageSize: this.tableObj.pageSize,
        pageNum: this.tableObj.pageNum,
      }
      this.listLoading = true
      const { code, message, result } = await searchLimitConsume(param);
      this.listLoading = false
      if(code !== 0) return this.$message.error(message);
      this.tableObj.list = result.list
      this.tableObj.total = result.total
    },
  }
};
</script>

<style lang="scss" scoped>
.record-detail{
  padding: 0 15px
}
.limit-top {
  margin: 16px 0;
  >div {
    height: 24px;
    line-height: 24px
  }
  .limit-desc {
    display: inline-block;
    min-width: 90px;
  }
}
.table-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  .cause-select {
    display: flex;
    align-items: center;
    >div {
      margin-right: 8px
    }
  }
}
</style>
